<template>
	<view class="user" :class="[isDark?'dark':'', AppStyle]" :style="{'background-color':isDark?'#1c1c1c':'#f6f6f6','min-height':isDark?'100vh':'auto'}">
		<view class="header" :style="[{height:CustomBar + 'px'}]">
			<view class="cu-bar" :class="isDark?'dark':'bg-white'" :style="{'height': CustomBar + 'px','padding-top':StatusBar + 'px','background-color':isDark?'#1c1c1c':'#ffffff'}">
				<view class="action" @tap="back">
					<text class="cuIcon-back"></text>
				</view>
				<view class="content text-bold" :style="[{top:StatusBar + 'px'}]">
					{{assetsname + $t('user.userwithdraw.cashout')}}
				</view>
				<view class="action" @tap="userwithdrawlist">
					<text class="cuIcon-edit"></text>
				</view>
			</view>
		</view>
		<view :style="[{padding:NavBar + 'px 10px 0px 10px'}]"></view>
		<br>
		<view class="cur-assets">{{$t('user.userwithdraw.current') + assetsname}}:<text class="text-red">{{assets}}</text></view>
		<form>
			
			<view class="cu-form-group margin-top">
				<view class="title">{{assetsname}}</view>
				<input placeholder="$t('user.userwithdraw.plscashoutnum')" name="input" type="number" v-model="num"/>
			</view>
		</form>
		<view class="all-btn margin-top">
			<view class="user-btn flex flex-direction" @tap="userwithdraw">
				
				<button class="cu-btn bg-blue margin-tb-sm lg">{{$t('user.userwithdraw.nowcashout')}}</button>
			</view>

			<view class="user-btn flex flex-direction" @tap="topay">
				<button class="cu-btn line-blue margin-tb-sm lg">{{$t('user.userwithdraw.paycodeset')}}</button>
			</view>
		</view>
		<view class="userrecharge-intro userwithdraw-box">
			<view class="userrecharge-intro-title">
				{{$t('user.userwithdraw.cashoutheed')}}:
			</view>
			<view class="userrecharge-intro-text">
				{{$t('user.userwithdraw.cashoutapply')}}<text class="text-red text-bold">{{$t('user.userwithdraw.oneday')}}</text>{{$t('user.userwithdraw.auditpayment')}}
			</view>
			<view class="userrecharge-intro-text">
				{{$t('user.userwithdraw.cashoutand') + assetsname + $t('user.userwithdraw.ratio')}}<text class="text-red text-bold"> 1:{{scale}} </text>,{{$t('user.userwithdraw.minicashout')}}<text class="text-red text-bold">{{$tixianed}}</text>{{assetsname}},{{$t('user.userwithdraw.willcharge')}}<text class="text-red text-bold">{{$tixiansx}}</text>%{{$t('user.userwithdraw.commission')}}。
			</view>
			<view class="userrecharge-intro-text">
				{{$t('user.userwithdraw.nocashpayreceiv')}}
			</view>
			<view class="userrecharge-intro-text">
				{{$t('user.userwithdraw.cashreviewstatus') + assetsname}}。
			</view>
		</view>
		<!--  #ifdef MP -->
		<view class="post-update bg-blue" @tap="userwithdraw">
			<text class="cuIcon-upload"></text>
		</view>
		<!--  #endif -->
	</view>
</template>

<script>
	import { localStorage } from '../../js_sdk/mp-storage/mp-storage/index.js'
	import darkModeMixin from '@/utils/darkModeMixin.js'
	export default {
		mixins: [darkModeMixin],
		data() {
			return {
				StatusBar: this.StatusBar,
				CustomBar: this.CustomBar,
				NavBar:this.StatusBar +  this.CustomBar,
				AppStyle:this.$store.state.AppStyle,
				tixiansx:"",
				num:"",
				assetsname:"",
				modalName:null,
				tixianed:1000,
				token:'',
				assets:"",
				scale:0,
			}
		},
		onPullDownRefresh(){
			
			
		},
		onShow(){
			var that = this;
			// #ifdef APP-PLUS
			plus.navigator.setStatusBarStyle("dark")
			// #endif
			that.userStatus();
			that.getVipInfo();
		},
		onLoad() {
			var that = this;
			// #ifdef APP-PLUS || MP
			that.NavBar = that.CustomBar;
			// #endif
		},
		mounted() {
			this.getset();
		},
		methods: {
			getset() {
				var that = this;
			    uni.request({
			        url:that.$API.SPset(),
			        method:'GET',
			        dataType:"json",
			        success(res) {
						that.tixianed = res.data.tixianed;
						that.assetsname = res.data.assetsname;
						that.tixiansx = res.data.tixiansx;
			        },
			        fail(error) {
						
			        }
			    })
			},
			back(){
				uni.navigateBack({
					delta: 1
				});
			},
			userwithdrawlist(){
				uni.navigateTo({
					url: '/pages/user/userwithdrawlist'
				});
			},
			userStatus() {
				var that = this;
				var token = "";
				if(localStorage.getItem('userinfo')){
					var userInfo = JSON.parse(localStorage.getItem('userinfo'));
					token=userInfo.token;
				}
				that.$Net.request({
					url: that.$API.userStatus(),
					data:{
						"token":token
					},
					header:{
						'Content-Type':'application/x-www-form-urlencoded'
					},
					method: "get",
					dataType: 'json',
					success: function(res) {
						if(res.data.code==1){
							that.assets = res.data.data.assets;
						}
					},
					fail: function(res) {
						uni.showToast({
							title: that.$t('common.networkfail'),
							icon: 'none'
						})
					}
				})
			},
			userwithdraw() {
				var that = this;
				if(that.num==""){
					uni.showToast({
					    title: that.$t('global.plsforminput'),
						icon:'none',
						duration: 1000,
						position:'bottom',
					});
					return false
				}
				if(that.num< that.tixianed){
					uni.showToast({
					    title: that.$t('user.userwithdraw.minicashout')+that.tixianed+that.assetsname,
						icon:'none',
						duration: 1000,
						position:'bottom',
					});
					return false
				}
				var token = "";
				if(localStorage.getItem('userinfo')){
					var userInfo = JSON.parse(localStorage.getItem('userinfo'));
					token=userInfo.token;
				}
				var data = {
					"num":that.num,
					"token":token,
				}
				uni.showLoading({
					title: that.$t('common.loadmore')
				});
				that.$Net.request({
					
					url: that.$API.userWithdraw(),
					data:data,
					header:{
						'Content-Type':'application/x-www-form-urlencoded'
					},
					method: "get",
					dataType: 'json',
					success: function(res) {
						setTimeout(function () {
							uni.hideLoading();
						}, 1000);
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
						if(res.data.code==1){
							var timer = setTimeout(function() {
								that.back();
							}, 1000)
						}
					},
					fail: function(res) {
						setTimeout(function () {
							uni.hideLoading();
						}, 1000);
						uni.showToast({
							title: that.$t('common.networkfail'),
							icon: 'none'
						})
						uni.stopPullDownRefresh()
					}
				})
			},
			topay(){
				uni.navigateTo({
				    url: '/pages/user/pay'
				});
			},
			getVipInfo(){
				var that = this;
				that.$Net.request({
					url: that.$API.getVipInfo(),
					header:{
						'Content-Type':'application/x-www-form-urlencoded'
					},
					method: "get",
					dataType: 'json',
					success: function(res) {
						if(res.data.code==1){
							that.scale=res.data.data.scale;
						}
						var timer = setTimeout(function() {
							that.isLoading=1;
							clearTimeout('timer')
						}, 300)
					},
					fail: function(res) {
						var timer = setTimeout(function() {
							that.isLoading=1;
							clearTimeout('timer')
						}, 300)
					}
				})
			},
		}
	}
</script>